#ifndef STREAMINGCLIENT
#define STREAMINGCLIENT

#include <cstdlib>
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>

#include <network\streamingConnection.h>

using std::string;

class streamingClient {
  
  boost::asio::io_service io_service;
  tcp::resolver *resolver;
  tcp::resolver::iterator endpoint_iterator;

  boost::thread *t;
  streamingConnection *new_connection;

  enum { 
    max_length = 1024 
  };

  char data_[max_length];

  static streamingClient *_instance;

private:

  void handle_read(const boost::system::error_code& error, size_t bytes_transferred);

  void do_write(const unsigned char *data, int size);
  void handle_write(const boost::system::error_code& error);

  // singleton
   streamingClient();
   streamingClient(const streamingClient &);
  ~streamingClient();

public:
  
  static streamingClient &instance();

  streamingConnection *connection();

  bool getModelDescription();
  void setCacheDir(string cachedir);
  void setLogin(string modelname, string username, string password);
  void setConnection(string server, string port);

  void start();
  bool isInitialized();
  void stop();

  void handle_connect(streamingConnection* new_connection, const boost::system::error_code& error, tcp::resolver::iterator endpoint_iterator);

  void destroy();
};

#endif
